<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript">
	function checkFrom() {
		if ($("#petName").val()=="") {
			alert("宠物昵称不能为空");
			return false;
		}
		if ($("select").val()==0) {
			alert("宠物品种不能为空");
			return false;
		}
		if ($("#saleStating").val()=="") {
			alert("发售起始日不能为空");
			return false;
		}
		if ($("#birtHday").val()=="") {
			alert("出生日期不能为空");
			return false;
		}

		//日期正则表达式
		var timeRegex1 = /^[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
		if(!timeRegex1.test($("#birtHday").val())){
			　　alert("日期格式不正确，正确格式为：yyyy-MM-dd");
			　　return false;
			}
		return true;
	}
	
	function judge(){
		$.post("JudgeServlet","petName="+$("#petName").val(),judgeFina,"JSON");
		function judgeFina(data){
			if(data != null){
				$("#span").html("宠物昵称以存在");
				$("#bc").attr("disabled","disabled");
			}else{
				$("#span").html("");
				$("#bc").removeAttr("disabled");
			}
		}
	}
	</script>
	<div>
		<h3 align="center">宠物的基本信息</h3>
		<form action="PetAddServlet" method="post" onsubmit="checkFrom()">
			昵称:&nbsp;&nbsp;&nbsp;<input name="petName" id="petName" onblur="judge()" type="text"><span id="span"></span><br> <br />
			品种:&nbsp;&nbsp;&nbsp;<select name="petBreed">
				<option value="0">--请选择--</option>
				<option value="1">狗</option>
				<option value="2">猫</option>
				<option value="3">鸟</option>
				<option value="4">兔</option>
			</select><br /> 性别:&nbsp;&nbsp;&nbsp;<input type="radio" name="petSex"
				value="1" checked="checked">雄&nbsp; <input type="radio" name="petSex"
				value="2">雌<br /> 出生日期:&nbsp;&nbsp;&nbsp;<input type="text"
				name="birtHday" id="birtHday">yyyy-MM-dd<br />
			<br /> 宠物描述:&nbsp;&nbsp;&nbsp;
			<textarea rows="2" cols="40" name="description"></textarea>
			<br /> <input type="submit" value="提交" id="bc">&nbsp;&nbsp;<input
				type="reset" value="重置">
		</form>
	</div>
</body>
</html>